import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/page/layout/Layout'

Vue.use(Router)

export const constantRouterMap = [
  {
    path: '',
    component: Layout,
    redirect: '/dashboard'
  },
  {
    path: '/login',
    component: () => import('@/page/login/login'),
    name: 'login',
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/page/login/register'),
    name: 'register',
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/page/errorPage/401'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/page/errorPage/404'),
    hidden: true
  },
  {
    path: '/dashboard',
    component: Layout,
    sidebar: true,
    meta: { title: '首页', icon: 'dashboard' },
    children: [
      {
        path: '',
        name: 'dashboard',
        sidebar: true,
        component: () => import('@/page/dashboard/Dashboard'),
        meta: { title: '首页', icon: 'dashboard', breadCrumb: true }
      }
    ]
  }
  // {
  //   path: '/testWebSocket',
  //   component: Layout,
  //   sidebar: true,
  //   meta: { title: '首页', icon: 'dashboard' },
  //   children: [
  //     {
  //       path: '',
  //       name: 'test',
  //       sidebar: true,
  //       component: () => import('@/page/html2'),
  //       meta: { title: '测试', breadCrumb: true }
  //     }
  //   ]
  // }
]

export default new Router({
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/user',
    component: Layout,
    sidebar: true,
    meta: { title: '用户', icon: 'user', authKey: 'user' },
    children: [
      {
        path: 'list',
        name: 'user',
        sidebar: true,
        component: () => import('@/page/user'),
        meta: { title: '用户管理', icon: 'user', authKey: 'user', breadCrumb: true }
      },
      {
        path: 'role',
        name: 'role',
        sidebar: true,
        component: () => import('@/page/user/role'),
        meta: { title: '角色管理', authKey: 'role', breadCrumb: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    meta: { title: '用户管理', breadCrumb: true },
    children: [
      {
        path: 'info/:userId/:infoFlag',
        name: 'userInfo',
        props: true,
        component: () => import('@/page/user/info'),
        meta: { title: '用户详情', authKey: 'user-detail', breadCrumb: true }
      }
    ]
  },
  {
    path: '/user/role',
    component: Layout,
    redirect: '/user/role',
    meta: { title: '角色管理', breadCrumb: true },
    children: [
      {
        path: 'new/:infoFlag',
        name: 'newRole',
        props: true,
        component: () => import('@/page/user/role/info'),
        meta: { title: '新增角色', authKey: 'role-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/user/role',
    component: Layout,
    redirect: '/user/role',
    meta: { title: '角色管理', breadCrumb: true },
    children: [
      {
        path: 'info/:roleId/:infoFlag',
        name: 'setRole',
        props: true,
        component: () => import('@/page/user/role/info'),
        meta: { title: '权限配置', authKey: 'role-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/user/role',
    component: Layout,
    redirect: '/user/role',
    meta: { title: '角色管理', breadCrumb: true },
    children: [
      {
        path: 'info/:roleId/:infoFlag',
        name: 'roleInfo',
        props: true,
        component: () => import('@/page/user/role/info'),
        meta: { title: '角色详情', authKey: 'role-detail', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    sidebar: true,
    meta: { title: '订单管理', icon: 'order', authKey: 'order' },
    children: [
      {
        path: 'list',
        name: 'order',
        sidebar: true,
        component: () => import('@/page/order'),
        meta: { title: '订单管理', icon: 'order', authKey: 'order', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', breadCrumb: true },
    children: [
      {
        path: 'new',
        name: 'newOrder',
        props: true,
        component: () => import('@/page/order/info'),
        meta: { title: '新增订单', authKey: 'order-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', breadCrumb: true },
    children: [
      {
        path: 'modify/:orderId',
        name: 'modifyOrder',
        props: true,
        component: () => import('@/page/order/info'),
        meta: { title: '修改订单', authKey: 'order-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', breadCrumb: true },
    children: [
      {
        path: 'judge/:orderId/:status',
        name: 'judgeOrder',
        props: true,
        component: () => import('@/page/order/judge'),
        meta: { title: '审核订单', authKey: 'order-judge', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', breadCrumb: true },
    children: [
      {
        path: 'childJudge/:childId/:status',
        name: 'judgeChildOrder',
        props: true,
        component: () => import('@/page/order/preJudge/childJudge'),
        meta: { title: '审核货物', authKey: 'order-judge', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', breadCrumb: true },
    children: [
      {
        path: 'detail/:orderId',
        name: 'orderDetail',
        props: true,
        component: () => import('@/page/order/detail'),
        meta: { title: '订单详情', authKey: 'order-detail', breadCrumb: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', breadCrumb: true },
    children: [
      {
        path: 'modifyAll/:orderId',
        name: 'modifyOrderAll',
        props: true,
        component: () => import('@/page/order/editDetail'),
        meta: { title: '修改订单', authKey: 'role-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/brand',
    component: Layout,
    sidebar: true,
    meta: { title: '品牌管理', icon: 'brand', authKey: 'brand' },
    children: [
      {
        path: 'list',
        name: 'brand',
        sidebar: true,
        component: () => import('@/page/brand'),
        meta: { title: '品牌管理', icon: 'brand', authKey: 'brand', breadCrumb: true }
      }
    ]
  },
  {
    path: '/brand',
    component: Layout,
    redirect: '/brand/list',
    meta: { title: '品牌管理', breadCrumb: true },
    children: [
      {
        path: 'new',
        name: 'newBrand',
        component: () => import('@/page/brand/info'),
        meta: { title: '新增品牌', authKey: 'brand-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/brand',
    component: Layout,
    redirect: '/brand/list',
    meta: { title: '品牌管理', breadCrumb: true },
    children: [
      {
        path: 'modify/:brandId',
        name: 'modifyBrand',
        component: () => import('@/page/brand/info'),
        meta: { title: '修改品牌', authKey: 'brand-edit', breadCrumb: true }
      }
    ]
  },
  {
    path: '/brand',
    component: Layout,
    redirect: '/brand/list',
    meta: { title: '品牌管理', breadCrumb: true },
    children: [
      {
        path: 'detail/:brandId',
        name: 'brandDetail',
        component: () => import('@/page/brand/detail'),
        meta: { title: '品牌订单', authKey: 'brand-detail', breadCrumb: true }
      }
    ]
  },
  {
    path: '/customer',
    component: Layout,
    sidebar: true,
    meta: { title: '客户管理', icon: 'customer', authKey: 'customer' },
    children: [
      {
        path: 'list',
        name: 'customer',
        sidebar: true,
        component: () => import('@/page/customer'),
        meta: { title: '客户管理', icon: 'customer', authKey: 'customer', breadCrumb: true }
      }
    ]
  },
  {
    path: '/customer',
    component: Layout,
    redirect: '/customer/list',
    meta: { title: '客户管理', breadCrumb: true },
    children: [
      {
        path: 'detail/:customerId',
        name: 'customerDetail',
        component: () => import('@/page/customer/detail'),
        meta: { title: '客户详情', authKey: 'customer-detail', breadCrumb: true }
      }
    ]
  },
  {
    path: '/notice',
    component: Layout,
    sidebar: true,
    meta: { title: '公告', icon: 'notice', authKey: 'notice' },
    children: [
      {
        path: '',
        name: 'notice',
        sidebar: true,
        component: () => import('@/page/notice'),
        meta: { title: '公告', icon: 'notice', authKey: 'notice', breadCrumb: true }
      }
    ]
  },
  {
    path: '/downLoad',
    component: Layout,
    sidebar: true,
    meta: { title: '下载', icon: 'downLoad', authKey: 'downLoad' },
    children: [
      {
        path: '',
        name: 'downLoad',
        sidebar: true,
        component: () => import('@/page/downLoad'),
        meta: { title: '下载', icon: 'downLoad', authKey: 'downLoad', breadCrumb: true }
      }
    ]
  },
  {
    path: '/error',
    component: Layout,
    redirect: 'noredirect',
    name: 'errorPages',
    meta: {
      title: 'errorPages',
      icon: '404'
    },
    children: [
      {
        path: '401', component: () => import('@/page/errorPage/401'), name: 'page401', meta: { title: 'page401', noCache: true }
      },
      {
        path: '404', component: () => import('@/page/errorPage/404'), name: 'page404', meta: { title: 'page404', noCache: true }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
